package cn.sccl.common.scheduler.controller;

import cn.sccl.common.model.PageResult;
import cn.sccl.common.scheduler.model.TaskFireLog;
import cn.sccl.common.scheduler.service.TaskFireLogManager;
import cn.sccl.common.web.BaseController;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* 定时调度任务日志表 的Controller
* Created by _minus on 2017-10-07.
*/
@RestController
@RequestMapping(value = "/framework/scheduler/taskFireLog")
public class TaskFireLogController extends BaseController {

    @Autowired
    private TaskFireLogManager taskFireLogManager;

    /**
    * 显示所有数据
    */
    @RequestMapping(value = "/all" , method = RequestMethod.GET)
    public List<TaskFireLog> listAllTaskFireLog(){
        return taskFireLogManager.listAll();
    }

    /**
    * 分页查询，分页参数放置在url路径中
    * @param pageIndex 页码
    * @param pageSize 分页大小
    * @param request
    * @return
    */
    @RequestMapping(value = "/page/{pageIndex}/{pageSize}" , method = RequestMethod.GET)
    public PageResult<TaskFireLog> pageQueryTaskFireLog(@PathVariable("pageIndex") long pageIndex , @PathVariable("pageSize") int pageSize , HttpServletRequest request){
        return taskFireLogManager.pageQueryByLike(pageIndex, pageSize, getQueryData(request));
    }

    /**
    * 分页查询，分页参数放置在request中
    * @param request
    * @return
    */
    @RequestMapping(value = "/page" , method = RequestMethod.GET )
    public PageResult<TaskFireLog> pageQueryTaskFireLog(HttpServletRequest request){
        return taskFireLogManager.pageQueryByLike(getPageIndex(request), getPageSize(request), getQueryData(request));
    }

    /**
    * 保存数据
    * @param taskFireLog
    * @return
    */
    @RequestMapping(value = "/" , method = RequestMethod.POST)
    public TaskFireLog saveTaskFireLog(@RequestBody TaskFireLog taskFireLog){
        taskFireLogManager.save(taskFireLog);
        return taskFireLog;
    }

    /**
    * 根据ID删除数据
    * @param id
    */
    @RequestMapping(value = "/{id}" , method = RequestMethod.DELETE)
    @JsonView(Object.class)
    public void deleteTaskFireLog(@PathVariable("id") String id){
        taskFireLogManager.delete(id);
    }
}
